package com.leff.cards.request;

import com.leff.cards.Dictionary;
import com.leff.cards.StoreWrapper;
import com.leff.cards.entity.Group;

public class SelectCard extends Request {
	
	public SelectCard(Dictionary dict) {
		super(dict);
	}
	
	public RequestResult doSelect() {
		
		RequestResult result = this.verifyRequiredParameters(Parameter.GROUP_ID, Parameter.CARD_IDS);
		if(!result.isSuccessful()) {
			return result;
		}
		
		long groupId = Long.valueOf((String)mDictionary.get(Parameter.GROUP_ID));
		Group G = StoreWrapper.getGroupById(groupId);
		if(G == null) {
			result.setErrorResult("No group found with ID " + groupId);
			return result;
		}
		
		String cardIds = (String)mDictionary.get(Parameter.CARD_IDS);
		G.selectSubmittedCards(cardIds);
		
		StoreWrapper.store(G);
		
		result.setSuccessMessage("Cards successfully selected for group");
		
		return result;
	}
}
